package tech.aistar.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;
import tech.aistar.pojo.UserLove;
import tech.aistar.service.UserLoveService;
import tech.aistar.vo.Result;
import tech.aistar.vo.ResultVo;


@RestController
@RequestMapping("userlove")
public class UserLoveController {
    @Autowired
    private UserLoveService userLoveService;



    @PostMapping ("/love")
    public Result love(UserLove userLove) {
        System.out.println(userLove);
        UserLove uLove = userLoveService.findByUserAndSid(userLove.getUId(), userLove.getSId());
        System.out.println(userLove.getUId());
        if ( userLove.getUId()!=null) {
            if (null == uLove) {
                userLoveService.insetBySingerName(userLove);
                return new Result("200", "喜欢成功");
            } else {
                return new Result("500", "已经存在这首歌");
            }

        }else{
            return new Result("405","请先登录");
        }

    }

    @RequestMapping(value = "/list",method = RequestMethod.GET)
    public ResultVo<UserLove> list(@RequestParam("page")Integer page,@RequestParam("limit")Integer limit,@RequestParam("uid")Integer uid) {

        return  userLoveService.findByUid(uid);
    }




}
